﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SiteMaster : System.Web.UI.MasterPage
{

    protected void Page_Load(object sender, EventArgs e)
    {
        
            load();
        
    }
    private void load()
    {

        CategoryDAO cate = new CategoryDAO();
        IList<Category> list = cate.Get_CategoryName();
        rpt_Category.DataSource = list;
        rpt_Category.DataBind();

        if (Session["member"] != null)
        {
            btnLogin.Text = "Logout";
            lb_member.Text = "You are sign in: " + Session["member"].ToString();
            pnLogin.Visible = false;
        }
        else
        {
            btnLogin.Text = "Login";
            pnLogin.Visible = true;
            lbLink.Visible = false;
            lb_member.Text = "";

        }
        
    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        UserDAO userlogin = new UserDAO();
        string user = txtUser.Text.ToString();
        string pass = txtPass.Text.ToString();
        
            if (btnLogin.Text == "Login")
            {
                if (userlogin.Login(user, pass))
                {
                    Session["member"] = txtUser.Text;
                    
                    if (Session["member"].ToString().Equals("admin"))
                        lbLink.Visible = true;
                    Page_Load(sender, e);    

                }
            }
            else
            {
                Session["member"] = null;
                Page_Load(sender, e);
                lbLink.Visible = false;
                txtUser.Text = "";
                txtPass.Text = "";
            }
        
    }

    private void Page_Load()
    {
        throw new NotImplementedException();
    }
}
